<?php 
	header("Content-type: application/json; charset=utf-8");
/*/
$con = mysql_connect("localhost", "root", "");
if (!$con)
{
  die('Could not connect: ' . mysql_error());
} else {
   mysql_select_db("dutoan_db", $con);
	$MaCT = mysql_real_escape_string($_POST['models'][0]['MaCT'], $con);
	$TenHM = mysql_real_escape_string($_POST['models'][0]['TenHM'], $con);
	
	$Khac =  mysql_real_escape_string($_POST['models'][0]['Khac'], $con);
	$sql = sprintf("INSERT INTO danhsachhangmuc(MaCT, TenHM, Khac) VALUES('%s', '%s', '%s')", $MaCT,$TenHM, $Khac);
   $rs = mysql_query($sql);
 
   if ($rs) {
    echo json_encode($rs);
 }
  else {
        header("HTTP/1.1 500 Internal Server Error");
        echo "Failed on insert: " . $_POST['models'][0]['Column1'];
  }
mysql_close($con);
}
/*/
//
	include("../include.php");	
	$verb = $_SERVER["REQUEST_METHOD"];
	if($verb == "POST")
	{
		$TenHM = mysql_real_escape_string($_POST['TenHM'], $link);
		$Khac = mysql_real_escape_string($_POST['Khac'], $link);
		$MaCT = mysql_real_escape_string($_POST['MaCT'], $link);
		//$Khac = mysql_real_escape_string($_POST["Khac"]);
		
		$sql = sprintf("insert into danhsachhangmuc(MaCT, TenHM, Khac) values ('%s','%s','%s')", $MaCT, $TenHM, $Khac);
		$rs = mysql_query($sql);
		
		if ($rs) {
       		echo json_encode($rs);
		}
		else {
			header("HTTP/1.1 500 Internal Server Error");
			echo "Không thể tạo mới hạng mục: " .$TenHM;
		}
		
	}
	echo $verb;
	
//	
?>